//
//  TSWalletHeaderView.swift
//  TSProfitProject
//
//  Created by TMS on 2019/11/8.
//  Copyright © 2019 TMS. All rights reserved.
//

import UIKit

class TSWalletHeaderView: UIView {

    var topHeader : UIView!
    var cashItemArray : [TSAccountHeaderCashItem] = []
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        configViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func updateHeaderViewFrame(offsetY:CGFloat) {
        topHeader.snp.updateConstraints { (make) in
            make.height.equalTo(96+offsetY)
        }
    }
    
    func configViews() {
        
        topHeader = UIView.init()
        topHeader.backgroundColor = BASE_PURPLE_COLOR
        addSubview(topHeader)
        topHeader.snp.makeConstraints { (make) in
            make.left.right.top.equalToSuperview()
            make.height.equalTo(96)
        }
        
        let itemContainer = UIImageView.init(image: UIImage(named: "main_cell_bg"))
        addSubview(itemContainer)
        itemContainer.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview().inset(15)
            make.bottom.equalToSuperview().inset(10)
            make.height.equalTo(140)
        }
        
        let centerItem = TSAccountHeaderCashItem.init("中心钱包")
        centerItem.setupCashItem(value: TSLoginManager.shared._usermodel?.zhongxin ?? 0)
        let coinItem = TSAccountHeaderCashItem.init("金币钱包")
        coinItem.setupCashItem(value: TSLoginManager.shared._usermodel?.jinbi ?? 0)
        let gainItem = TSAccountHeaderCashItem.init("盈利钱包")
        gainItem.setupCashItem(value: TSLoginManager.shared._usermodel?.yingli ?? 0)
        let profitItem = TSAccountHeaderCashItem.init("收益钱包")
        profitItem.setupCashItem(value: TSLoginManager.shared._usermodel?.yongjin ?? 0)
        
        cashItemArray.append(gainItem)
        cashItemArray.append(profitItem)
        cashItemArray.append(centerItem)
        cashItemArray.append(coinItem)
        
        var itemX : CGFloat = 0
        var itemY : CGFloat = 0
        let itemW = (SCREEN_WIDTH - 2*12) * 0.5
        let itemH : CGFloat = 70.0
        for index in 0..<cashItemArray.count {
            let item = cashItemArray[index]
            itemX = index % 2 == 0 ? 5 : itemW
            itemY = index / 2 >= 1 ? 5 : itemH
            item.frame = CGRect(x: itemX, y: itemY, width: itemW, height: itemH)
            itemContainer.addSubview(item)
        }
        
        let horizonLine = UIView.init()
        horizonLine.backgroundColor = UIColor.hexadecimalColor(hexadecimal: "#E9EDF5")
        itemContainer.addSubview(horizonLine)
        horizonLine.snp.makeConstraints { (make) in
            make.left.right.centerY.equalToSuperview()
            make.height.equalTo(1)
        }
        
        let verticalLine = UIView.init()
        verticalLine.backgroundColor = UIColor.hexadecimalColor(hexadecimal: "#E9EDF5")
        itemContainer.addSubview(verticalLine)
        verticalLine.snp.makeConstraints { (make) in
            make.centerX.top.bottom.equalToSuperview()
            make.width.equalTo(1)
        }
    }

}
